package FiveHomeworkDesign.Iterator;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

/**
 * @author 北巷_东坡
 * @date 2022/11/21 21:55
 * @computer 10741
 */
public class Class206 {
    List<Student206> slist=null;
    public Class206(){
        Student206[] stu=new Student206[5];
        slist=new ArrayList<Student206>();
        stu[0]=new Student206("张三", 32);
        stu[1]=new Student206("李四", 25);
        stu[2]=new Student206("王五", 21);
        stu[3]=new Student206("赵六", 38);
        stu[4]=new Student206("周七", 26);
        for(int i=0;i<5;i++){
            slist.add(stu[i]);
        }
    }
    public void display(){
        Iterator<Student206> t=slist.iterator();
        System.out.println("遍历获得的原始数据：");
        while(t.hasNext()){
            Student206 student=t.next();
            System.out.println("姓名："+student.getName()+"今年"+student.getAge()+"岁");
        }
        Collections.sort(slist);
        Iterator<Student206> it=slist.iterator();
        System.out.println("========================================");
        System.out.println("按年龄从大到小排序：");
        while(it.hasNext()){
            Student206 student=it.next();
            System.out.println("姓名："+student.getName()+"今年"+student.getAge()+"岁");
        }
    }
}
